package com.my.mymafengwo.activity;

import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.view.SurfaceView;
import android.widget.ImageView;

import com.my.mymafengwo.R;
import com.my.mymafengwo.base.WithMediaPlayerActivity;

/**
 * ***********************************************
 * author:wgh
 * time:2015/12/2 16:10
 * copyright:
 * name:
 * step:
 * ***********************************************
 */
public class SplashActivity extends WithMediaPlayerActivity {

    /**
     * 欢迎页下方的视频控件
     */
    private SurfaceView sv;
    private ImageView iv;

    private Handler handler = new Handler();

    @Override
    protected void loadXml() {
        setContentView(R.layout.activity_splash);
    }

    @Override
    protected void getIntentData(Bundle savedInstanceState) {

    }

    @Override
    protected void initViews() {
        sv = (SurfaceView) findViewById(R.id.sv_splash);
        iv = (ImageView) findViewById(R.id.iv_splash);
    }

    @Override
    protected void registerListener() {

    }

    @Override
    protected void initData() {
//        handler.postDelayed(new Runnable() {
//            @Override
//            public void run() {
        playMedia(sv, R.raw.splash_animation);
//            }
//        }, 300);
    }

    @Override
    public void onCompletion(MediaPlayer mp) {
        super.onCompletion(mp);
        System.out.println("onCompletion");
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                intoNextActivity();
            }
        }, 3000);
    }

    private void intoNextActivity() {
        startActivity(new Intent(this, WelcomeActivity.class));
        finish();
    }
}
